package com.fxw.hodgepodge.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.fxw.hodgepodge.R;
import com.fxw.mylibrary.BaseAppContext;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author xianwen.fu
 * @version v1.0
 * @Title 父类activity 所有activity 继承该类
 * @Description:
 * @date 2016/10/15 10:30
 */
public abstract class BaseActivity extends AppCompatActivity {
    protected BaseActivity mContext;
    protected BaseAppContext mApplication;
    protected Toolbar mToolbar;
    protected Unbinder mUnBinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        setContentView(getLayoutResId());
    }

    protected abstract int getLayoutResId();

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mUnBinder.unbind();
        mApplication.finishActivity(this);
    }

    private void init() {
        mContext = this;
        mApplication = (BaseAppContext) getApplication();
        mApplication.addActivity(this);
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        mUnBinder = ButterKnife.bind(mContext);
        mToolbar = (Toolbar) findViewById(R.id.tb_toolbar);
        if (mToolbar != null) {
            setSupportActionBar(mToolbar);
            getSupportActionBar().setTitle("");
            getSupportActionBar().setSubtitle("");
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            mToolbar.setNavigationIcon(com.fxw.mylibrary.R.drawable.ic_backward);
        }
        initDatas();
        initListeners();
    }

    protected abstract void initListeners();

    protected abstract void initDatas();

}

